package com.bdilab.iot.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bdilab.iot.model.Role;
import com.bdilab.iot.model.UserRoleRelation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author WangNing
 * @version 1.0
 * @date 2020/7/31 16:52
 */
@Mapper
public interface UserRoleRelationMapper extends BaseMapper<UserRoleRelation> {


    int insertBatch(List<UserRoleRelation> relations);

    @Delete("delete from `user_role_relation` where `user_id` = #{userId}")
    int deleteByUserId(Long userId);

    @Select("select r.id as id ,r.name as name, r.description as description, r.create_time as create_time, r.update_time as update_time from user_role_relation as urr\n" +
            "left join role r on urr.role_id = r.id\n" +
            "where urr.user_id = #{userId};")
    List<Role> getRolesByUserId(Long userId);

}
